﻿using System;

namespace MvcFlow.Diagnostics
{
    public enum LogLevel
    {
        Debug       = 0,
        Info        = 1,
        Warning     = 2,
        Error       = 3,
        Critical    = 4,
    }

    public interface ILog
    {
        void Write(LogLevel level,string message, params object[] parameters);
        void WriteException(LogLevel level,string message, Exception exception);
    }

    internal class NullLog : ILog
    {
        public void Write(LogLevel level, string message, params object[] parameters)
        { }

        public void WriteException(LogLevel level, string message, System.Exception exception)
        { }
    }

    public static class LogExtensions
    {
        public static void Debug(this ILog log, string message, params object[] parameters)
        {
            log.Write(LogLevel.Debug, message, parameters);
        }

        public static void DebugException(this ILog log, string message, Exception exception)
        {
            log.WriteException(LogLevel.Debug, message, exception);
        }

        public static void Info(this ILog log,string message,params object[] parameters)
        {
            log.Write(LogLevel.Info,message,parameters);
        }

        public static void InfoException(this ILog log,string message,Exception exception)
        {
            log.WriteException(LogLevel.Info,message,exception);
        }

        public static void Warning(this ILog log, string message, params object[] parameters)
        {
            log.Write(LogLevel.Warning, message, parameters);
        }

        public static void WarningException(this ILog log, string message, Exception exception)
        {
            log.WriteException(LogLevel.Warning, message, exception);
        }

        public static void Error(this ILog log, string message, params object[] parameters)
        {
            log.Write(LogLevel.Error, message, parameters);
        }

        public static void ErrorException(this ILog log, string message, Exception exception)
        {
            log.WriteException(LogLevel.Error, message, exception);
        }

        public static void Critical(this ILog log, string message, params object[] parameters)
        {
            log.Write(LogLevel.Critical, message, parameters);
        }

        public static void CriticalException(this ILog log, string message, Exception exception)
        {
            log.WriteException(LogLevel.Critical, message, exception);
        }
    }
}